package com.zhaowei.allinpay;

import ime.service.client.SOAClient;
import ime.service.util.RSAUtil;
import org.json.JSONObject;

import java.security.PrivateKey;
import java.security.PublicKey;

public class DemoPortal {
//    //商户号
//    static String sysid = "100000000002";
//    //密钥密码
//    static String pwd = "697057";
//    //证书名称
//    static String alias = "100000000002";
//    //证书文件路径，用户指定
//    static String path = "G:\\JavaWeb\\pfx\\100000000002.pfx";
//    
    //商户号
    static String sysid = "100009001000";
    //密钥密码
    static String pwd = "900724";
    //证书名称
    static String alias = "100009001000";
    //证书文件路径，用户指定
    static String path = "E:\\JavaSpace\\YTest\\pfx\\100009001000.pfx";
    
    //加密方法
    static String signMethod = "SHA1WithRSA";
    //SOA接口地址
    static String serverAddress = "http://122.227.225.142:23661/service/soa";
    //SDK
    private static SOAClient client;
    //公钥
    private static PublicKey publicKey;
    //私钥
    private static PrivateKey privateKey;
    //每个接口handler的工厂
    private static DemoHandlerFactory demoHandlerFactory;

    public static void main(String[] args) {
        try {
            //初始化
            init();

            //服务对象
//            String serviceName = "MemberService";
            //调用方法
//            String methodName = "createMember";          //创建会员
//            String methodName = "sendVerificationCode";  //发送短信验证码
//            String methodName = "bindPhone";             //绑定手机
//            String methodName = "changeBindPhone";       //重置绑定手机（短信验证码确认）
//            String methodName = "setRealName";           //个人实名认证
//            String methodName = "setCompanyInfo";        //设置企业信息
//            String methodName = "getMemberInfo";         //获取会员信息
//            String methodName = "getBankCardBin";        //查询卡bin
//            String methodName = "applyBindBankCard";     //请求绑定银行卡
//            String methodName = "bindBankCard";          //确认绑定银行卡
//            String methodName = "setSafeCard";           //设置安全卡
//            String methodName = "queryBankCard";         //查询绑定银行卡
//            String methodName = "unbindBankCard";        //解绑绑定银行卡
//            String methodName = "lockMember";            //锁定会员
//            String methodName = "unlockMember";          //解锁会员

            String serviceName = "OrderService";
//            String methodName = "depositApply";          //充值申请
//            String methodName = "withdrawApply";         //提现申请
           String methodName = "consumeApply";          //消费申请
//              String methodName = "agentCollectApplySimplify"; //托管代收申请（简化版）
//            String methodName = "signalAgentPaySimplify";    //单笔托管代付（简化版）
//            String methodName = "batchAgentPaySimplify";     //批量托管代付（简化版）
//            String methodName = "pay";                   //确认支付（后台+短信验证码确认）
//            String methodName = "entryGoods";            //商品录入
//            String methodName = "queryModifyGoods";      //查询、修改商品
//            String methodName = "freezeMoney";           //冻结金额
//            String methodName = "unfreezeMoney";         //解冻金额
//            String methodName = "refund";                //退款申请
//            String methodName = "failureBidRefund";      //流标专用退款
//            String methodName = "applicationTransfer";   //平台转账
//            String methodName = "queryBalance";          //查询余额
  //          String methodName = "getOrderDetail";        //查询订单状态
//            String methodName = "queryInExpDetail";      //查询收支明细

//            String serviceName = "MerchantService";
//            String methodName = "queryReserveFundBalance"; //通联通头寸查询
//            String methodName = "getCheckAccountFile";   //平台集合对账下载

            IDemoHandler handler = demoHandlerFactory.getHandler(serviceName, methodName);
            JSONObject params = handler.getRequestParams();
            System.out.println("请求参数：" + params.toString());
            JSONObject response = client.request(serviceName, methodName, handler.getRequestParams());
            System.out.println("返回数据：" + response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void init() {
        try {
            publicKey = RSAUtil.loadPublicKey(alias, path, pwd);
            privateKey = RSAUtil.loadPrivateKey(alias, path, pwd);
            client = new SOAClient();
            client.setServerAddress(serverAddress);
            client.setSignKey(privateKey);
            client.setPublicKey(publicKey);
            client.setSysId(sysid);
            client.setSignMethod(signMethod);

            demoHandlerFactory = new DemoHandlerFactory();

            DemoUtils.setParams(publicKey, privateKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
